#ifndef MODULE_HPLC_AUTOSAMPLER_DEFINE_H
#define MODULE_HPLC_AUTOSAMPLER_DEFINE_H

#include <QVector>
#include "modulehplcdefine.h"

namespace hplc
{

typedef struct
{
    uint8_t hour;
    uint8_t minute;
    uint8_t second;
}Time_t;

typedef struct
{
    uint8_t	columnNumber;
    uint8_t	rowNumber;
}ColumnRow_t;

typedef struct
{
    quint8	plateNumber; // [1~3]
    union
    {
        ColumnRow_t	columnRowNumber;
        quint16		vialNumber; // 当plateNumber == 3 时
    };
}SamplePosition_t;

typedef enum
{
    InjectionMode_None,
    InjectionMode_PartialLoopFill,
    InjectionMode_FullLoop,
    InjectionMode_uLPickUp,
}InjectionMode_t;

typedef enum
{
    SytingeSpeed_Low = 1,
    SytingeSpeed_Normal,
    SytingeSpeed_High,
}SyringeSpeed_t;

typedef enum
{
    Status_NotRunning = 0,
    Status_Running = 10,
    Status_SearchVial = 20,
    Status_Flushing = 30,
    Status_AnalysisTimeRunning = 40,
    Status_FillingSampleLoop = 50,
    Status_FreezeActive = 51,
    Status_SparkLinkInjectMarker = 55,
    Status_Washing = 60,
    Status_MissingVial = 80,
    Status_Rinsing_uLPickUp = 90,
    Status_WithdrawTransportSolvent_ulPickUp = 110,
    Status_FillTransport = 111,
    Status_RinseBuffer = 120,
    Status_Despensing_InMix = 130,
    Status_Aspirating_InMix = 140,
    Status_PullingAirBeforeAspirateSample_InMix = 150,
    Status_WaitingForProspekt2LoadCommand = 151,
    Status_WaitingForNextInjectCommand = 152,
    Status_WaitingForNextInjectSyncCommand = 153,
    Status_WaitingForLoadSyncCommand = 154,
    Status_WaitingForInjectSyncCommand = 155,
    Status_WaitingForValveWashSyncCommand = 156,
    Status_WaitingTimeDuringMix = 159,
    Status_Mixing = 160,
    Status_InjectorValveToInject_UserProg = 170,
    Status_InjectorValveToLoad_UserProg = 171,
    Status_InjectorValveToNeedleWasteOrWash_UserProg = 172,
    Status_SyringeLoad_UserProg = 173,
    Status_SyringeUnload_UserProg = 174,
    Status_SyringeHome_UserProg = 175,
    Status_MoveTray_UserProg = 176,
    Status_MoveNeedleHorizontal_UserProg = 177,
    Status_MoveNeedleVertical_UserProg = 178,
    Status_WaitForInput_UserProg = 180,
    Status_WaitForEvent1_UserProg = 181,
    Status_WaitForEvent2_UserProg = 182,
    Status_WaitForEvent3_UserProg = 183,
    Status_WaitForEvent4_UserProg = 184,
    Status_WaitForEvent5_UserProg = 185,
    Status_WaitForEvent6_UserProg = 186,
    Status_WaitForEvent7_UserProg = 187,
    Status_WaitForEvent8_UserProg = 188,
    Status_WaitForEvent9_UserProg = 189,
    Status_WaitForEvent10_UserProg = 191,
    Status_WaitForEvent11_UserProg = 192,
    Status_WaitForEvent12_UserProg = 193,
    Status_WaitForEvent13_UserProg = 194,
    Status_WaitForEvent14_UserProg = 195,
    Status_WaitForEvent15_UserProg = 196,
    Status_TrayRunning = 200,
    Status_SyringeOrSyringeValveRunning = 201,
    Status_NeedleRunning = 202,
    Status_InjectionValveRunning = 203,
    Status_ISSARunning = 204,
    Status_InitializingMotors = 310,
    Status_ProcessingStop = 900,
    Status_InitialWashFromReady = 910,
    Status_PrimeSolventSelectionValve = 920,
    Status_MovingSyringeToHomePosition = 921,
    Status_MovingSyringeToEndPosition = 922,
    Status_MovingSyringeToExchangePosition = 928,
}Status_t;

typedef struct
{
    uint8_t isError;
    Status_t status;
}StatusEx_t;

typedef struct
{
    uint8_t leftType; // [0~4]
    uint8_t rightType; // [0~4]
}SeparatePlateType_t;

typedef struct
{
    uint8_t	leftTrayType; // [0/3]
    uint8_t rightTrayType; // [0/3]
    union
    {
        SeparatePlateType_t	separatePlateType;
        quint16		singlePlateType; // 当leftTrayType == 3 && rigthTrayType == 3 时 [33]
    };
}TraySegmentSetting_t;

typedef struct
{
    uint8_t isSyncWithValveWash;
    uint8_t isSyncWithInject;
    uint8_t isSyncWithLoad;
    uint8_t isSyncWithNextInjection;
}SyncCondition_t;

typedef enum
{
    WashBetween_None = 0,
    WashBetween_Vials = 2,
    WashBetween_Injection = 3,
}WashBetween_t;

typedef struct
{
    uint8_t steps; // [1~9]
    uint8_t times; // [1~9]
}WashTimesEx_t;

typedef enum
{
    WashSyringeValveSolventPort_WashPort1 = 1,
    WashSyringeValveSolventPort_NeedlePort = 2,
    WashSyringeValveSolventPort_WastePort = 3,
    WashSyringeValveSolventPort_WastePort2 = 4,
}WashSyringeValveSolventPort_t;

typedef struct
{
    uint8_t steps;
    WashSyringeValveSolventPort_t port;
}WashSyringeValveSolventPortEx_t;


typedef struct
{
    uint8_t port; // [0/1]
    uint8_t times; // [1~9]
}FillTransportPositionTimes_t;

typedef struct
{
    uint8_t steps;
    uint16_t volume;
}WashVolumeEx_t;

typedef struct
{
    uint8_t isUseTimedEvents;
    uint8_t isUseMix;
}UseInMethod_t;

typedef struct
{
    uint8_t ai;
    uint8_t startUserProg;
    uint8_t startOrStop; // 启动/停止 [0/1]
}StartOrStopEx_t;

typedef enum
{
    SpecialPosition_TrayHome = 107,
    SpecialPosition_ExchangeNeedlePosition = 108,
    SpecialPosition_TrayFront = 109,
}SpecialPosition_t;

typedef struct
{
    uint8_t plateNumber; // [0~4]
    union
    {
        SpecialPosition_t 	specialPosition; // 当plateNumber == 4 时
        uint16_t 			platePosition; // 当plateNumber == 1 or 2 时
        uint16_t 			singlePlatePosition; // 当plateNumber == 3 时
    };
}SearchSamplePosition_t;

typedef struct
{
    uint8_t port;
    uint8_t startInitialWash; // 开始/结束清洗
}InitialWash_t;

typedef enum
{
    MoveSyringe_HomePosition = 0,
    MoveSyringe_EndPosition,
    MoveSyringe_ExchangePosition,
}MoveSyringe_t;

// 自动进样器的所有参数
struct AutoSamplerParam : public CommonParam
{
    // 0100
    Time_t _analysisTime;
    uint32_t analysisTime; // 分析时长，s [[0~9]:[00~59]:[00~59]]
    // 0107
    uint16_t loopVolume; // 进样体积 ul [0000~5000]
    // 0108
    SamplePosition_t firstSamplePosition; // 开始瓶号
    // 0109
    SamplePosition_t lastSamplePosition; // 结束瓶号
    // 0111
    uint16_t flushVolume; // 清洗体积 ul [0000~9999]
    // 0112
    uint8_t numberOfInjectionsOrSample; // 进样次数 [1~9]
    // 0124
    InjectionMode_t injectionMode; // 进样模式
    // 0125
    uint16_t syringeVolume; // 注射器体积 ul [00250/00500/01000 or 02500 in pre mode]
    // 0126
    uint16_t tubingVolume; // 定量环体积 ul [000~999]
    // 0128
    SamplePosition_t firstTransportVial; //
    // 0129
    SamplePosition_t lastTransportVial; //

    // 0130
    uint8_t sampleNeedleHeight; // 针高度 mm [2.0~6.0mm in step 0.5mm] ?
    // 0131
    SyringeSpeed_t syringeSpeed; // 注射速度
    // 0132
    uint8_t syringeSpeedScaleFactor; // 注射速度比例因子 [01~10]
    // 0134
    uint16_t bufferVolume; // 缓冲环体积 ul [0000~9999,default 500]
    // 0150
    SamplePosition_t actualSampleNumber; // 实际采集瓶号

    // 0152
    StatusEx_t status; // 状态 三位数，如果有错误则第4位数为1

    // 0155
    uint16_t _errorCode; // 错误代码
    // 0156 重置错误状态 第一位为1则清除所有错误

    // 0192
    uint8_t airSegment; // 空气段? [0/1]
    // 0193
    uint8_t skipMissingSamplePosition; // 跳过空瓶 [0/1]
    // 0194
    uint8_t headSpacePressure; // 顶空压 [0/1]
    // 0195
    uint8_t resetOutputAfterSerials; // 序列结束后强制复位数字输出 [0/1]
    // 0198
    uint8_t usePrepMode; // 使用制备模式 preparation mode [0/1]

    // 0200
    TraySegmentSetting_t traySegmentSettings; // 样品盘型号(布局)
    // 0208
    SyncCondition_t syncCondition; // 清洗、下一针、进样、清洗阀是否同步进行
    // 0210
    uint16_t injectionVolume; // 注射体积 ul [00000~09999]/[00000~19999 in prep mode]

    // 0500
    WashBetween_t washBetween; // 清洗模式，样品瓶之间/进样之间
    // 0501
    WashTimesEx_t washTimes; // 清洗次数 [1~9]
    // 0502
    WashSyringeValveSolventPortEx_t washSyringeValveSolventPort; // 清洗注射器阀溶剂口
    // 0505
    FillTransportPositionTimes_t fillTransportPositionTimes; //
    // 0507
    WashVolumeEx_t washVolume; // 清洗体积 [0000~9999]

    // 0540
    UseInMethod_t useInMethod; // 是否在方法中启用时间事件和混合功能

    // 1000
//    uint32_t programmedValue; //
    // 1001
//    uint32_t actualValue; //

    // 2509
    uint32_t _serialNumber; // 序列号

    // 4005
    uint8_t clearMixOrUserProg; // 清空混合方法 [1]
    // 4008
    uint8_t clearMethod; // 清空进样方法 [1]

    // 5100
    StartOrStopEx_t startOrStop; // 启动/停止 [0/1]
    // 5101
    uint8_t holdOrContinue; // 暂停/继续 [0/1]
    // 5111
    SearchSamplePosition_t searchSamplePosition; // 移入/移出托盘
    // 5130
    InitialWash_t initialWash; // 开始/结束清洗
    // 5140
    MoveSyringe_t moveSyringe; // 设置注射器位置
    // 5300
    uint8_t doorSensor; // 门传感器，没用
};

} // namespace hplc

Q_DECLARE_METATYPE(hplc::Time_t)
Q_DECLARE_METATYPE(hplc::SamplePosition_t)
Q_DECLARE_METATYPE(hplc::InjectionMode_t)
Q_DECLARE_METATYPE(hplc::SyringeSpeed_t)
Q_DECLARE_METATYPE(hplc::StatusEx_t)
Q_DECLARE_METATYPE(hplc::TraySegmentSetting_t)
Q_DECLARE_METATYPE(hplc::SyncCondition_t)
Q_DECLARE_METATYPE(hplc::WashBetween_t)
Q_DECLARE_METATYPE(hplc::WashTimesEx_t)
Q_DECLARE_METATYPE(hplc::WashSyringeValveSolventPortEx_t)
Q_DECLARE_METATYPE(hplc::FillTransportPositionTimes_t)
Q_DECLARE_METATYPE(hplc::WashVolumeEx_t)
Q_DECLARE_METATYPE(hplc::UseInMethod_t)
Q_DECLARE_METATYPE(hplc::StartOrStopEx_t)
Q_DECLARE_METATYPE(hplc::SearchSamplePosition_t)
Q_DECLARE_METATYPE(hplc::InitialWash_t)
Q_DECLARE_METATYPE(hplc::MoveSyringe_t)

#endif // MODULE_HPLC_AUTOSAMPLER_DEFINE_H
